<template>
	<view class="box">
		<view class="select-realse">
			<view class="realse-title">
				一定要离开蜜袋互助大家庭吗？
			</view>
			<view class="propt-resale">
				请选选择退出原因（最多三项）
			</view>
			<view class="realse-list flex flai" v-for="(item,index) in list" :key="item.id" @click="selectRealse(index)">
				<image src="../../static/image/noSelect.jpg" mode="" v-if="!item.isSelect"></image>
				<image src="../../static/image/select.jpg" mode="" v-else></image>
				<text>{{item.name}}</text>
			</view>
		</view>
		<view class="footer-btn flex flai">
			<view class="flex1" @click="waive">
				放弃保障
			</view>
			<view class="flex1" @click="backPrev">
				我再想想
			</view>
		</view>
		<view class="mask" v-if="isShowMask">
			<view class="waive-pouple">
				<image src="../../static/image/realse_1.png" mode=""></image>
				<view class="pouple-box">
					<view class="">
						放弃保障后，您的资产将不再支撑互助计划，您将于下一个结算日开始享受电站收益，并可在指定时间进行提现！
					</view>
					<view class="pouple-bottom flex">
						<view class="flex1" @click="waiveCofirm">
							放弃保障
						</view>
						<view class="flex1" @click="againThink">
							我再想想
						</view>
					</view>
					
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import {addNotScroll,removeNotScroll} from '../../static/common.js'
	import api from '../../api/index.js'
	export default {
		data () {
			return {
				isShowMask:false,
				list:[
						{isSelect:false,name:'不信任蜜袋互助'},
						{isSelect:false,name:'已加入其他互助平台/保险'},
						{isSelect:false,name:'年龄不符合加入要求'},
						{isSelect:false,name:'保障人信息填写错误'},
						{isSelect:false,name:'不了解什么是互助就加入了'},
						{isSelect:false,name:'蜜袋互助信息透明度不够'},
						{isSelect:false,name:'担忧隐私泄露'},
						{isSelect:false,name:'保障额度太低'},
						{isSelect:false,name:'其他'},
					
					],
					selectArr:[],
					id:''
			}
		},
		onLoad(opt) {
			this.id = opt.id
		},
		mounted () {
			
		},
		methods:{
			// 选择原因
			selectRealse(index) {
				this.list[index]['isSelect']=!this.list[index]['isSelect']
			},
			// 放弃
			waive() {
				var list = this.list
				var arr = []
				for (var k in list) {
					if (list[k].isSelect) {
						arr.push({isSelect:list[k].isSelect,name:list[k].name})
					}
				}
				this.selectArr = arr
				if (arr.length<1) {
					uni.showToast({
					    title: '请至少选择一个原因',
					    duration: 2000,
						icon:'none'
					});
					return
				}else
				if (arr.length>3) {
					uni.showToast({
					    title: '最多选择三个原因',
					    duration: 2000,
						icon:'none'
					});
					return
				} else {
					// 提交
					this.isShowMask = true
					addNotScroll()
					
				}
			},
			// 确定放弃
			waiveCofirm(){
				var str=''
				for (var k in this.selectArr){
					str+=this.selectArr[k].name+','
				}
				var data = {
					id:this.id,
					reason:str
				}
				api.myHelp.waiveSalf(data).then(res=>{
					if (res.code == 1){
						uni.showToast({
							title:'操作成功'
						})
						setTimeout(()=>{
						uni.navigateBack({
							delta:3
						})
						},2000)
					}
					
				})
			},
			// 再想想
			againThink () {
				this.isShowMask = false
				removeNotScroll()
				uni.navigateBack({
					delta:2
				})
			},
			// 返回前二页
			backPrev(){
				uni.navigateBack({
					delta:2
				})
			}
		}
	}
</script>

<style>
	@import "../../static/css/common.css";
	@import url("./myMutualHelp.css");
</style>
